#include "MLNumGen_Normal.h"
_MYLABLIB_BEGIN

CMLNumGen_Normal::CMLNumGen_Normal(const std::vector<double>& vMean, 
																		   const std::vector<double>& vVariance)
{
	ML_ASSERT(vMean.size() == vVariance.size());

	m_vMean = vMean;
	m_vVariance = vVariance;
	m_nNumDimensions = (int)vMean.size();
	m_vStandardDeviation.resize(m_vMean.size());
	int d;
	for (d=0; d<m_nNumDimensions; d++)
	{
		m_vStandardDeviation[d] = sqrt(vVariance[d]);
	}
}

CMLNumGen_Normal::~CMLNumGen_Normal(void)
{
}

CMLDataPoint CMLNumGen_Normal::Generate(void)
{
	CMLDataPoint p;
	p.resize(m_nNumDimensions);
	int i;
	for (i=0; i<m_nNumDimensions; i++)
	{
		p[i] = Generate1D(m_vMean[i], m_vStandardDeviation[i]);
	}
	return p;
}

double CMLNumGen_Normal::Generate1D(double dMean, double dDeviation)
{
	double a = m_UniGen1.Generate()[0];
	double b = m_UniGen2.Generate()[0];
	return dMean + sqrt(-2.0*log(a)) * cos(2*M_PI*b)* dDeviation;
}

_MYLABLIB_END